package com.nineclock.approve.resolver;

import com.alibaba.fastjson.JSONObject;
import com.nineclock.approve.resolver.abs.ProcessNodeResolver;
import org.activiti.bpmn.model.Process;
import org.activiti.bpmn.model.UserTask;
import org.springframework.stereotype.Component;

/**
 * 审批节点处理器
 */
@Component
public class ApproveNodeResolver extends ProcessNodeResolver {

    private final String type = "approval";

    @Override
    public boolean support(String nodeType) {
        return nodeType.equals(type);
    }

    @Override
    public void addFlowNodeToActiviti(Process process, JSONObject curNode, JSONObject nextNode) {
        // 创建节点
        UserTask userTask = new UserTask();
        userTask.setId(getNodeId(curNode));
        userTask.setName(curNode.getString("name"));

        process.addFlowElement(userTask);

        // 绘制连线
        newSequenceFlow(process, curNode, nextNode);

    }
}
